/** ###################################################################
**     Filename  : EM.h
**     Project   : parking
**     Processor : MC9S12XS128MAL
**     Compiler  : CodeWarrior HCS12X C Compiler
**     Date/Time : 2013-3-9, 11:09
**     Contents  :
**         User source code
**
** ###################################################################*/

#ifndef __EM_H
#define __EM_H

/* MODULE EM */

#include "AD.h"
#include "Types.h"


#define EM_LEFT_FRONT_CHANNEL	(0)
#define EM_RIGHT_FRONT_CHANNEL	(1)
#define EM_LEFT_BACK_CHANNEL	(2)
#define EM_RIGHT_BACK_CHANNEL	(3)

#define EM_READ_COUNT_MAX	(20)
#define EM_VALUE_DEFAULT	(0)
#define EM_CORRECTION_DEFAULT_FRONT	(5)	 //20130330
#define EM_CORRECTION_DEFAULT_BACK	(2)	  //20130330
#define EM_DIR_SCALE_FRONT	(5)
#define EM_DIR_SCALE_BACK	(3)
#define EM_DIR_MIDDLE_THRESHOLD	(15)
#define EM_DIR_MIDDLE_FRONT_THRESHOLD (10)
#define EM_DIR_SLOPE_THRESHOLD	(0)		//20130330
#define EM_DIR_SLOPE_CORRECTION	(4) 	//20130330
#define EM_DIR_SLOPE_SCALE (6)

#define EM_HISTORY_LEN	(10)
#define EM_DETECT_THRESHOLD	(155)	//20130330

extern U8 EMLeftFrontValue;
extern U8 EMRightFrontValue;
extern U8 EMLeftBackValue;
extern U8 EMRightBackValue;
extern S16 EMCorrectionFront;
extern S16 EMCorrectionBack;
void EMStart(void);
void EMStop(void);
void EMIrqHandler(void);
S16 EMGetValueFront(void);
S16 EMGetValueBack(void);
void EMDriveForward(void);
void EMDriveBackward(void);
void EMInit(void);
U16 EMDirFilter(U16 dir);


/* END EM */

#endif

